import json
from openai import OpenAI
import re
import random



class ChatAi():
    def __init__(self):
        pass


    def predbailian(self,prompt):
        client = OpenAI(
            api_key="sk-79c4febbe6854062ae2eb64c87251453",
            base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
        )
        completion = client.chat.completions.create(
            # model="qwen-turbo",
            model="qwen-plus",
            messages=[
                {'role': 'system', 'content': 'You are a helpful assistant.'},
                {'role': 'user', 'content': prompt}],temperature=0.001
        )
        content = completion.choices[0].message.content.strip()
        return content
    def predbailian1(self,cust1):

        cust=cust1["text"]
        prompt = f'''
        You are a copywriter and your task is to rephrase 30 texts similar to an example text of a customer from a dialog with the certain brand car salesperson's.
        The customer's 【example text】is : “{cust}”
        
        The generated texts need to be a rephrase of the 【example text】 using the same tone/topic/content.
        The generated texts need the same intention as the 【example text】, for example, greeting or introducing oneself.
        If the customer mentions the vehicle brand, the generated texts need still use the same vehicle brand.
        If the customer mentions their surname, the generated texts can change the surname.
        If the customer inquires about a certain car spare part, the generated script should not delve into the detailed features of the part.
        Please output in a list of strings format, without line breaks like \n.
        
        Format example:["text1","text2","text3","text4","text5","text6","text7","text8","text9","text10","text11","text12","text13","text14","text15","text16","text17","text18","text19","text20","text21","text22","text23","text24","text25","text26","text27","text28","text29","text30"]
        
        '''

        # print(prompt)
        result=self.predbailian(prompt)
        print(result)
        return result


if __name__ == '__main__':
    ChatAi()
